package queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:测试阻塞队列
 * User: bjc
 * Date: 2025-08-25
 * Time: 21:55
 */
public class QueueDemo1 {
    public static void main(String[] args) throws InterruptedException {
        //创建阻塞队列的对象，容量是10
        BlockingQueue<String> queue = new ArrayBlockingQueue<>(10);
        //存储元素
        queue.put("aaa");//put方法源代码有异常，所以调用需要处理异常
        //获取元素
        String s = queue.take();//如果获取不到就会阻塞
        System.out.println("第一次获取："+ s);
        s = queue.take();
        System.out.println("第二次获取："+ s); //获取不到就会阻塞
    }
}
